package com.yoda.youdianda.dto;

import com.yoda.youdianda.common.RC;
import com.yoda.youdianda.domain.SysRole;
import com.yoda.youdianda.vo.MenuDetailVo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author shawn
 * @date 2022年 11月 12日 20:17
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RoleInfoDto {
    private String id;
    private String name;
    private String description;
    private String create_date;
    private String update_date;
    private String del_flag;
    private Integer superadmin;
    private String default_data;
    private List<MenuDetailVo> authList;
    private List<Integer> menuids;

    public static SysRole init(RoleInfoDto dto) throws ParseException {
        SysRole role = new SysRole();
        SimpleDateFormat format = new SimpleDateFormat(RC.GENERAL_DATE_FORMAT);
        BeanUtils.copyProperties(dto,role);
        role.setDelFlag(dto.getDel_flag());
        role.setDefaultData(dto.getDefault_data());
        role.setCreateDate(format.parse(dto.getCreate_date()));
        role.setUpdateDate(format.parse(dto.getUpdate_date()));
        return role;
    }
}
